from django import template
from django.utils.safestring import mark_safe
import markdown
import re

register = template.Library()

@register.filter(name='markdown_safe')
def markdown_safe(value):
    """将markdown格式的文本转换为HTML"""
    if value:
        # 转换markdown为HTML
        html = markdown.markdown(value, extensions=['extra', 'codehilite'])
        return mark_safe(html)
    return '' 